package com.yugao.fintech.libra.workflow.controller;

import com.yugao.fintech.meheco.core.domain.ResultVO;
import com.yugao.fintech.meheco.core.web.controller.BaseController;
import com.yugao.fintech.meheco.core.web.page.TableDataInfo;
import com.yugao.fintech.meheco.log.annotation.Log;
import com.yugao.fintech.meheco.log.enums.BusinessType;
import com.yugao.fintech.draper.security.annotation.InnerApi;
import com.yugao.fintech.draper.security.annotation.RequiresPermissions;
import com.yugao.fintech.libra.workflow.api.model.AuditConfig;
import com.yugao.fintech.libra.workflow.service.IAuditConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审核配置
 */
@RestController
@RequestMapping("/auditConfig")
public class AuditConfigController extends BaseController {
    @Autowired
    private IAuditConfigService auditConfigService;

    @RequiresPermissions("workflow:auditConfig:list")
    @GetMapping("/list")
    public TableDataInfo list(AuditConfig auditConfig) {
        startPage();
        List<AuditConfig> list = auditConfigService.list(auditConfig);
        return getDataTable(list);
    }

    @RequiresPermissions("workflow:auditConfig:status:edit")
    @AutoLog(summary = "审核配置", businessType = BusinessType.UPDATE)
    @PutMapping("/status/edit")
    public com.yugao.fintech.meheco.core.web.domain.AjaxResult editStatus(@RequestBody AuditConfig auditConfig) {
        return toAjax(auditConfigService.editStatus(auditConfig));
    }

    @RequiresPermissions("workflow:auditConfig:cache:refresh")
    @AutoLog(summary = "审核配置", businessType = BusinessType.CLEAN)
    @DeleteMapping("/cache/refresh")
    public com.yugao.fintech.meheco.core.web.domain.AjaxResult refreshCache() {
        auditConfigService.refreshCache();
        return com.yugao.fintech.meheco.core.web.domain.AjaxResult.success();
    }

    @InnerApi
    @GetMapping("/inner/info/{code}")
    public ResultVO<AuditConfig> getInfoByCode(@PathVariable("code") String code) {
        return ResultVO.success(auditConfigService.queryByCode(code));
    }
}
